<template>
  <a-modal
    title="借阅档案"
    :visible="visible"
    width="1000px"
    height="1000px"
    @ok="handleSubmit"
    title-align="start"
    :ok-loading="loading"
    @cancel="
      () => {
        emit('update:visible', false);
      }
    "
  >
    <a-row style="width: 100%">
      <pro-table
        style="width: 100%"
        ref="proTableRef"
        :formType="searchType"
        :request="request"
        :tableType="tableType"
        rowKey="arc_id"
        showRows
      >
      </pro-table>
    </a-row>
  </a-modal>
</template>
<script setup lang="ts">
  import { ref, watch } from 'vue';
  import useLoading from '@/hooks/loading';
  import { deletearch, getarchiveList } from '@/api/archives';
  import { Message } from '@arco-design/web-vue';
  const { loading, setLoading } = useLoading(false);
  import { TableInstance } from '@arco-design/web-vue';
  import { omit } from 'lodash';
  import cloneDeep from 'lodash/cloneDeep';
  const proTableRef = ref<TableInstance | null>(null);
  const props = defineProps({
    visible: Boolean,
    type: Number || String,
  });
  const emit = defineEmits(['update:visible', 'selectArchives']);
  const currentKey = ref(1);
  const tableType = [
    { dataIndex: 'arc_id', slotName: 'id' },
    {
      title: '档案编号',
      dataIndex: 'arc_code',
    },
    {
      dataIndex: 'arc_name',
      title: '档案名称',
    },
    {
      title: '类别',
      dataIndex: 'arc_cate_name',
      align: 'center',
    },

    {
      title: '存放位置',
      children: [
        {
          title: '所属档案柜',
          dataIndex: 'arc_cabinet_name',
          align: 'center',
        },
        {
          title: '栏',
          dataIndex: 'arc_cabinet_row',
          align: 'center',
        },
        {
          title: '格',
          dataIndex: 'arc_cabinet_col',
          align: 'center',
        },
      ],
    },
    {
      title: '是否借出-还没弄',
      dataIndex: 'user_remarks',
      slotName: 'status',
      options: [
        {
          status: 'success',
          value: 1,
          label: '已借出',
        },
        {
          status: 'danger',
          value: 2,
          label: '未借出',
        },
      ],
    },
  ];
  async function request(params: any) {
    const res = await getarchiveList({
      ...params,
      arc_type: props.type,
    });
    return {
      data: res.data,
    };
  }
  const searchType = ref([
    {
      name: 'arc_code',
      label: '档案编号',
      type: 'a-input',
      fieldProps: {
        span: 8,
      },
    },
    {
      name: 'arc_name',
      label: '档案名称',
      type: 'a-input',
      fieldProps: {
        span: 8,
      },
    },
  ]);

  // watch(currentKey, async () => {
  //   if (proTableRef.value) {
  //     await proTableRef.value.setRefresh();
  //   }
  // });

  function handleSubmit() {
    // 处理提交逻辑
    if (proTableRef.value?.selectItems.length === 0) {
      Message.warning('请至少选择一个档案进行操作');
      return;
    }
    emit('selectArchives', cloneDeep(proTableRef.value?.selectItems));
    emit('update:visible', false);
  }
</script>

<style scoped lang="less"></style>
